<?php
session_start();
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

if ($_REQUEST["HidId"] <> "") {
    $tabla = "solotb_empresa";
    switch ($_REQUEST["opc"]) {
        case "M":
            $tipo = "UPDATE";
        //'Valida si no se ha modificado nada, regresa con OK
            if ($_REQUEST["TxtDesc"] == $_REQUEST["TxtDesc0"])
                header ("Location: solotrn_empresa2.php?MiError=0");

            $strSql = "$tipo $tabla set ";
            $strSql .=  "des='" . $_REQUEST["TxtDesc"] . "' ";
            $strSql .=  "where id=" . $_REQUEST["HidId"];

            //'ruta=server.MapPath("/documentacion") & "\" & $_REQUEST["TxtDesc0")

            //'Set fso = Server.CreateObject("Scripting.FileSystemObject")
            //'Set f = fso.GetFolder(ruta)
            //'f.Name=$_REQUEST["TxtDesc")
//		       'if err<>0 then
//				 ' header ("Location: trn_empresas.asp?MiError=1&des=" & err.description
//		          'response.write err & "-" &err.description
//			      'response.end
//		       'end if
            break;
        case "E":
            $tipo = "DELETE";
            $strSql = "$tipo from $tabla where id=" . $_REQUEST["HidId"];
            break;
        default:
            $tipo = "INSERT";
            $strSql = "$tipo into $tabla values (";
            $strSql .=  $_REQUEST["HidId"] . ",'";
            $strSql .=  $_REQUEST["ATxtDesc"] . "')";
            break;
    }

    $arrQueries = array();
    array_push($arrQueries, $strSql);
    array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));
    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);

//   'OJO REVISAR PARA QUE SE REALICE BORRADO EN CASCADA
//   'O BIEN BORRAR EN TODAS LAS TABLAS ASOCIADAS
//  ' if $_REQUEST["opc")="E" then
//	'  Set DataConn = Server.CreateObject("ADODB.Connection")
//     ' set DataComm = Server.CreateObject("ADODB.Command")
//	  'DataConn.Open Session("Soloconn")
//	  'DataComm.ActiveConnection = Session("SoloConn")
//	  'DataComm.CommandType = 1
//	  'DataComm.CommandText = "delete from solotb_nivel2 where id1=" & $_REQUEST["hidId")
//	  'Datacomm.execute
//	  'DataConn.close()
//  'end if

    //if(!$oConexion->EjecutarQuery($strSql))
    if(!$oConexion->EjecutarTransaccion($arrQueries))
//'	 response.write STRsqL & err.description
        $strMsg = "solotrn_empresas2.php?MiError=1&des=" . $oConexion->getErrorMessage();
    else
        $strMsg = "solotrn_empresas2.php?MiError=0";

    $oConexion->Cerrar();
    header("Location: $strMsg");
}

//'CODIGO CUANDO SE SUBMITE LA PAGINA
switch ($_REQUEST["opc"]) {
    case "M":
        $boton ="<input type='submit' name='CmdGrabar' value='Modificar' class='SoloStyle_boton'>";
        $oculto = "<input type='hidden' name='opc' value='M'>";
        $titulo="Modificaci&oacute;n de Empresa";
        break;
    case "E":
        $boton ="<input type='submit' name='CmdGrabar' value='Eliminar' class='SoloStyle_boton'>";
        $oculto = "<input type='hidden' name='opc' value='E'>";
        $titulo = "Eliminaci&oacute;n de Empresa";
        break;
//'		  case "C"
//'		       boton ="<input type='button' name='CmdGrabar' value='Regresar' class='boton' Onclick='javascript:history.back();'>"
//'		       titulo="Consulta de Categor�as"
//'              strSql="select * from tb_empresas_categoria where id1=" & $_REQUEST["id" )& " order by ds_tran"
//
//'               set Obj=Server.CreateObject("ADODB.Recordset")
//'               Obj.Open strSql,Session("conn")
//'               if err<>0 then
//'                  strERROR=1
//'                  err=0
//'               end if
//'               arrData=Obj.Getrows()
//'               set Obj=Nothing
}

?>
<html>
    <head>
        <title>Documentaci&oacute;n</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
    </head>

    <body topmargin=0 leftmargin=0>
        <p align="center"class="SoloStyle_titulopaginas"><?php echo $titulo;?></p>

        <?php if ($_REQUEST["opc"] <> "C") {?>
        <form name="frmIngreso" action="trn_GrabaEmpresa2.php" method="POST">
            <table border="0" width="70%" align="center">
                <tr>
                    <td class="SoloStyle_etiqueta"><b>Id</b></td>
                    <td class="solostyle_texto"><?php echo $_REQUEST["id"];?><input type="hidden" maxlenght="50" size="50" name="HidId" class="texto" value="<?php echo $_REQUEST["id"];?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_etiqueta"><b>Nueva Empresa</b></td>
                    <td><input type="text" maxlenght="50" size="50" name="TxtDesc" class="SoloStyle_Texto" value="<?php echo $_REQUEST["ds"];?>"><input type="hidden" maxlenght="50" size="50" name="TxtDesc0" class="solostyle_texto" value="<?php echo $_REQUEST["ds"];?>"></td>
                </tr>
            </table>
            <br><center><?php echo $boton;?><?php echo $oculto;?></center>
        </form>
        <br/>
            <?php }else {?>
        <table width="75%" border="0" align="center" class="grid">
            <tr class="SoloStyle_etiqueta"> 
                <td>Empresa: <?php echo $_REQUEST["ds"];?></td>
            </tr>
                <?php for ($i = 0; $i < count($arrData); $i++) {?>
            <tr>
                <td><?php echo $arrData[$i][2];?></td>
            </tr>
                    <?php }?>
        </table>
        <br><center><?php echo $boton;?></center>
            <?php } ?>
    </body>
</html>